home *** CD-ROM | disk | FTP | other *** search
-
- ; CM-MACS.LIB - By CFMartin - 2/15/90
- ;
- ; A Collection of Standard Assembly Macros written for use with the
- ; Wolfware Assembler WASM, and the interrupt service provided by CM-INT.COM
- ;
- ; General Notes:
- ; 1. These macros are not necessarily compatible with any assembler
- ; except WASM.
- ; 2. Arguments for these macros are of two types, denoted by the
- ; suffixes "_lab" and "_imm", for "label" and "immediate," based
- ; on the expected most frequent usage.
- ; a. _lab indicates that the macro is looking for a
- ; label for a memory operand in the data segment.
- ; b. _imm indicates that the macro is looking for an immediate
- ; operand. To reference memory in the data segment, just
- ; enclose the operand label in brackets.
- ; 3. Names and syntax of some macros will look very familiar to
- ; C programmers, as they are patterned after standard C functions
-
- ; VIDEO/KEYBOARD MANAGEMENT
-
- ;------------------
- vpage macro vpage_imm ;selects video page
- ;------------------
- ; vpage_imm byte video page number to be selected
- ;------------------
- mov ah,5
- mov al,vpage_imm
- int 10h
- endm
-
- ;------------------
- vmode macro vmode_imm ;sets video mode
- ;------------------
- ; vmode_num byte video mode number
- ;------------------
- mov ah,0
- mov al,vmode_imm
- int 10h
- endm
-
- ;------------------
- poscurs macro row_imm,column_imm ;positions cursor on active page (mode 2,3)
- ;------------------
- ; row_imm,column_imm bytes 0,0=upper left corner
- ;------------------
- mov ah,0Fh ;get video state
- int 10h
- mov ah,2 ;service 2 -- position cursor
- mov dh,row_imm ;bh contains page
- mov dl,column_imm
- int 10h ;set cursor
- endm
-
- ;------------------
- clrscrn macro color_imm ;clears active screen page (mode 2,3)
- ;------------------
- ; color_imm byte attribute to clear screen with
- ;------------------
- mov ah,0Fh ;get video state
- int 10h
- mov al,bh ;page
- mov ah,0
- mov bx,100h ;256 paras per page modes 2 & 3
- mul bx
- add ax,0B800h ;seg of page 0
- mov es,ax
- mov dl,color_imm
- mov di,0
- mov ah,dl
- mov cx,2000
- mov al,20h ;blank
- cld
- rep
- stosw
- endm
-
- ;------------------
- pause macro key_name_imm ;pauses until the named key is pressed
- ;------------------
- ; key_name_imm byte key to wait for
- ;------------------
- mov bl,byte key_name_imm
- mov bh,00h
- int 0C0h
- endm
-
-
- ;------------------
- print macro str_lab ;print string at current cursor pos on active page
- ;------------------
- ; str_lab byte label of ASCIIZ string to print
- ;------------------
- lea si,str_lab
- mov bh,01h
- int 0C0h
- endm
-
- ;------------------
- input macro str_lab ;input string to <Rtn> with echo to active page
- ;------------------
- ; str_lab byte label of ASCIIZ destination string
- ;------------------
- lea si,str_lab
- mov bh,02h
- int 0C0h
- endm
-
- ;------------------
- scan macro prompt_lab,data_lab,data_len_imm
- ;------------------
- ; prompt_lab byte label of ASCIIZ prompt string
- ; data_lab byte label of ASCIIZ dest string for input
- ; data_len_imm byte unsigned length of dest string
- ; (Use no filtering, no blank stripping, window color 0Fh)
- ;------------------
- lea si,prompt_lab
- lea di,data_lab
- mov al,data_len_imm
- mov ah,0 ;no input data filtering
- mov cl,0 ;no blank stripping
- mov ch,0Fh ;window color=hi intens wh, blk bkgd
- mov bx,300h ;upper and lower case accepted
- int 0C0h
- endm
-
- ;------------------
- lprint macro str_lab
- ;------------------
- ; Prints ASCIIZ string at ds:offset str_lab to parallel printer
- ;------------------
-
- mov cx,-1
- lea si,str_lab
- mov bh,4
- int 0C0h
- endm
-
- ;------------------
- lprintc macro ctrl_str_lab
- ;------------------
- ; Prints printer control string at ds:offset ctrl_str_lab to parallel printer
- ; First byte of control string is length; remainder is string
- ;------------------
-
- mov cl,[ctrl_str_lab]
- xor ch,ch
- lea si,ctrl_str_lab
- inc si
- mov bh,4
- int 0C0h
- endm
-
-
-
- ; NUMERICAL CONVERSION
-
- ;------------------
- ltoa macro dw_lab,str_lab ;convert 32-bit number to decimal ASCIIZ string
- ;------------------
- ; dw_lab double word 32-bit number to be converted
- ; str_lab byte label of ASCIIZ dest string in ds
- ;------------------
- lea si,str_lab
- mov ax,[offset dw_lab] ;low order 16 bits
- mov dx,[offset dw_lab+2] ;high order 16 bits,
- ;including sign (bit 31)
- mov bl,0 ;decimal return
- mov bh,06h
- int 0C0h
- endm
-
- ;------------------
- ltoa2 macro dw_lab,str_lab,base_imm ;convert with base option
- ;------------------
- ; dw_lab double word 32-bit number to be converted
- ; str_lab byte label of ASCIIZ dest string in ds
- ; base_imm byte dec=0,hex=1,oct=2,bin=3
- ;------------------
- lea si,str_lab
- mov ax,[offset dw_lab] ;low order 16 bits
- mov dx,[offset dw_lab+2] ;high order 16 bits,
- ;including sign (bit 31)
- mov bl,base_imm
- mov bh,06h
- int 0C0h
- endm
- ;------------------
- atol macro dw_lab,str_lab ;conv string to 32-bit d-word
- ;------------------
- ; dw_lab double word 32-bit number to be converted
- ; str_lab byte label of ASCIIZ source string in ds
- ;------------------
- lea si,str_lab
- mov bh,07h
- int 0C0h
- mov [offset dw_lab],ax ;low order 16-bits
- mov [offset dw_lab+2],dx ;high order 16-bits
- endm
-
- ;------------------
- itoa macro w_lab,str_lab ;conv signed 16-bit word to dec string
- ;------------------
- ; w_lab word signed 16-bit number to be converted
- ; str_lab byte label of ASCIIZ dest string in ds
- ;------------------
- lea si,str_lab
- mov ax,[offset w_lab] ;16-bit signed no.
- cwd ;extend to d-word
- mov bl,0 ;return decimal
- mov bh,06h
- int 0C0h
- endm
-
- ;------------------
- itoa2 macro w_lab,str_lab,base_imm ;conv signed 16-bit word to string
- ;------------------
- ; w_lab word signed 16-bit number to be converted
- ; str_lab byte label of ASCIIZ dest string in ds
- ; base_imm byte dec=0,hex=1,oct=2,bin=3
- ;------------------
- lea si,str_lab
- mov ax,[offset w_lab] ;16-bit signed no.
- cwd ;extend to d-word
- mov bl,base_imm
- mov bh,06h
- int 0C0h
- endm
- ;------------------
- atoi macro w_lab,str_lab ;conv string to signed 16-bit
- ;------------------
- ; w_lab word signed 16-bit number to be converted
- ; str_lab byte label of ASCIIZ source string in ds
- ;------------------
- lea si,str_lab
- mov bh,07h
- int 0C0h
- mov [offset w_lab],ax ;if -32768 > i > 32787, lose
- ;the significant bits
- endm
-
- ;------------------
- utoa macro w_lab,str_lab ;conv unsigned 16-bit to dec string
- ;------------------
- ; w_lab word unsigned 16-bit number to be converted
- ; str_lab byte label of ASCIIZ dest string in ds
- ;------------------
- lea si,str_lab
- mov ax,[offset w_lab]
- mov dx,0
- mov bl,0 ;return decimal string
- mov bh,06h
- int 0C0h
- endm
-
- ;------------------
- utoa2 macro w_lab,str_lab,base_imm ;conv unsigned 16-bit to string
- ;------------------
- ; w_lab word signed 16-bit number to be converted
- ; str_lab byte label of ASCIIZ dest string in ds
- ; base_imm byte dec=0,hex=1,oct=2,bin=3
- ;------------------
- lea si,str_lab
- mov ax,[offset w_lab]
- mov dx,0
- mov bl,base_imm
- mov bh,06h
- int 0C0h
- endm
- ;------------------
- atou macro w_lab,str_lab ;conv string to unsigned 16-bit
- ;------------------
- ; w_lab word unsigned 16-bit number to be converted
- ; str_lab byte label of ASCIIZ source string in ds
- ;------------------
- lea si,str_lab
- mov bh,07h
- int 0C0h
- mov [offset w_lab],ax ;if i>65535, lose the significant bits
- endm
-
- ; DATE/TIME CONVERSION
-
- ;------------------
- caltojul macro jul_lab,cal_lab ;converts calendar string to julian
- ;------------------
- ; jul_lab word julian date destination
- ; cal_lab byte label of ASCIIZ source string date in ds
- ; (Century prefix is returned in bl)
- ;------------------
- lea si,cal_lab
- mov bh,11h
- int 0C0h
- mov [offset jul_lab],ax
- ;NOTE: If the calendar string
- ;date has a 2-digit yr, 19 is assumed as
- ;the century prefix
- endm
-
- ;------------------
- jultocal macro jul_lab,cal_lab ;converts julian to calendar string
- ;------------------
- ; jul_lab word julian date destination
- ; cal_lab byte label of ASCIIZ source string date in ds
- ;------------------
- lea si,cal_lab
- mov bh,10h
- mov bl,19 ;all dates are assumed to have cent pref 19,
- ;and the display will have 2 digits in the year
- ;If 4 digits are desired, or date other than in
- ;century prefix 19, use jultocal4 below
- mov ax,[offset jul_lab]
- mov cx,2 ;two digit display for year
- int 0C0h
- endm
-
- ;------------------
- jultocal4 macro century_lab,jul_lab,cal_lab ;4-digit year display
- ;------------------
- ; century_lab byte century prefix (eg, 21 for the year 2167)
- ; jul_lab word julian date destination
- ; cal_lab byte label of ASCIIZ source string date in ds
- ;------------------
- lea si,cal_lab
- mov bh,10h
- mov bl,[century_lab]
- mov ax,[jul_lab]
- mov cx,4 ;display 4 digits of year
- int 0C0h
- endm
-
- ;------------------
- getdate macro cal_lab ;puts system date string into cal_lab
- ;------------------
- ; cal_lab byte label of ASCIIZ source string date in ds
- ;------------------
- lea si,cal_lab
- mov bh,12h
- mov cx,2 ;two-digit year display (assumption is
- ;century prefix=19)
- int 0C0h
- endm
-
- ;------------------
- setdate macro cal_lab ;sets system date to string in cal_lab
- ;------------------
- ; cal_lab byte label of ASCIIZ source string date in ds
- ;------------------
- lea si,cal_lab
- mov bh,13h
- int 0C0h
- endm
-
- ;------------------
- timetostr macro time_lab,str_lab
- ;------------------
- ; time_lab double word number of seconds since the previous midnight
- ; str_lab byte label of ASCIIZ string time format hh:mm:ss
- ;------------------
- lea si,str_lab
- mov ax,[time_lab]
- mov dx,[time_lab + 2]
- mov bh,15h
- int 0C0h
- endm
-
- ;------------------
- strtotime macro time_lab,str_lab
- ;------------------
- ; time_lab double word number of seconds since the previous midnight
- ; str_lab byte label of ASCIIZ string time format hh:mm:ss
- ;------------------
- lea si,str_lab
- mov bh,16h
- int 0C0h
- mov [time_lab],ax
- mov [time_lab + 2],dx
- endm
-
- ;------------------
- gettime macro time_lab,str_lab ;gets current time from system
- ;------------------
- ; time_lab double word number of seconds since the previous midnight
- ; str_lab byte label of ASCIIZ string time format hh:mm:ss
- ;------------------
- lea si,str_lab
- mov bh,17h
- int 0C0h
- mov [time_lab],ax
- mov [time_lab + 2],dx
- endm
-
- ;------------------
- settime macro str_lab ;sets system time
- ;------------------
- ; str_lab byte label of ASCIIZ string time format hh:mm:ss
- ;------------------
- lea si,str_lab
- mov bh,18h
- int 0C0h
- endm
-
- ;------------------
- timer macro
- ;------------------
- ; Returns:
- ; dx:ax double word number of seconds since last midnite
- ; bx word number of seconds elapsed since last call
- ;------------------
- mov bh,19h
- int 0C0h
- endm
-
- ; STRING MANAGEMENT
-
- ;------------------
- strcpy macro dest_lab,source_lab
- ;------------------
- ; dest_lab byte label of ASCIIZ dest string in ds
- ; source_lab byte label of ASCIIZ source string in ds
- ;------------------
- lea si,source_lab
- lea di,dest_lab
- push ds
- pop es
- mov bh,20h
- int 0C0h
- endm
-
- ;------------------
- strlen macro string_lab
- ;------------------
- ; string_lab byte label of ASCIIZ source string in ds
- ; Returns:
- ; ax word length of string
- ;------------------
- lea si,string_lab
- mov bh,21h
- int 0C0h
- endm ;str length is in ax
-
- ;------------------
- strcat macro dest_lab,source_lab
- ;------------------
- ; dest_lab byte label of ASCIIZ dest string in ds
- ; source_lab byte label of ASCIIZ source string in ds
- ;------------------
- lea di,dest_lab
- lea si,source_lab
- mov bh,22h
- int 0C0h
- endm
-
- ;------------------
- strcmp macro str_1_lab,str_2_lab,len_imm
- ;------------------
- ; str_1_lab,str_2_lab bytes labels in ds of ASCIIZ strings
- ; len_imm word maximum length of comparison
- ; Compares str1 to str2. Returns:
- ; ax=0 if strings are equal, ax=1 if str1>str2, ax=-1 if str1<str2
- ; bx=position number of first unequal byte (first position is 0)
- ;------------------
- lea si,str_1_lab
- lea di,str_2_lab
- mov cx,len_imm
- mov bh,23h
- int 0C0h
- endm
-
- ;------------------
- strswap macro str_1_lab,str_2_lab,len_imm
- ;------------------
- ; str_1_lab,str_2_lab bytes labels in ds of ASCIIZ strings
- ; len_imm word number of bytes to swap
- ;------------------
- lea si,str_1_lab
- lea di,str_2_lab
- mov cx,len_imm
- mov bh,24h
- int 0C0h
- endm
-
- ;------------------
- strimbed macro dest_lab,source_lab
- ;------------------
- ; dest_lab,source_lab bytes labels in ds of ASCIIZ strings
- ; Imbeds (copies without terminal NULL) source into destination
- ;------------------
- lea si,source_lab
- lea di,dest_lab
- mov bh,25h
- int 0C0h
- endm
-
- ;------------------
- allcaps macro string_lab
- ;------------------
- ; string_lab byte label in ds of ASCIIZ string
- ; Capitalizes all lower case letters in string at string_lab
- ;------------------
- lea si,string_lab
- mov cx,0 ;max of 32768 chars
- mov bh,26h
- int 0C0h
- endm
-
-
- ; MEMORY MANAGEMENT
-
- ;------------------
- dealloc macro
- ;------------------
- ; Deallocates all memory excess to immediate code needs + 512 bytes for
- ; stack.
- ;------------------
- STACK_BYTES equ 200h ;stack to equal 512 bytes
- mov ax,$SIZE
- add ax,100h ;for PSP
- add ax,STACK_BYTES
- mov sp,ax
-
- mov cl,4
- shr ax,cl
- inc ax ;1 para buffer
- mov bx,ax
- push cs
- pop es
- mov ah,4Ah
- int 21h ;memory reallocated
- endm
-
- ;------------------
- alloc macro no_paras_imm,memseg_lab
- ;------------------
- ; Allocates no_paras_imm paragraphs, puts memory segment in memseg_lab.
- ; If asking for a lot, check carry flag for error
- ; memseg_lab = word label
- ;------------------
- mov bx,no_paras_imm
- mov ah,48h
- int 21h
- mov [memseg_lab],ax
- endm
-
- ;------------------
- alloc_all macro no_paras_lab,memseg_lab
- ;------------------
- ; Allocates all available memory, puts memory segment in memseg_lab, and
- ; number of paragraphs available in no_paras_lab.
- ; memseg_lab,no_paras_lab = word labels
- ;------------------
- mov bx,0FFFFh ;ask for impossible
- mov ah,48h
- int 21h
- mov ah,48h
- mov [no_paras_lab],bx
- int 21h
- mov [memseg_lab],ax
- endm
-
- ;------------------
- freemem macro memseg_lab
- ;------------------
- ; Frees the block of memory identified by the segment stored in memseg_lab.
- ; memseg_lab = word label
- ;------------------
- mov es,[memseg_lab]
- mov ah,49h
- int 21h
- endm
-
- ;------------------
- xmemput macro dest_seg_lab,dest_off_lab,source_name_lab,num_imm
- ;------------------
- ; Put string into extended memory from data segment
- ; dest_seg_lab word in memory containing segment of destination block
- ; dest_off_lab word in memory containing offset of destination block
- ; source_name_lab byte label of source block in ds
- ; num_imm word number of bytes to move
- ;------------------
- mov ax,[dest_seg_lab]
- mov es,ax
- mov di,[dest_off_lab]
- lea si,source_name_lab
- mov cx,num_imm
- cld
- rep
- movsb
- endm
-
- ;------------------
- xmemget macro dest_name_lab,source_seg_lab,source_off_lab,num_imm
- ;------------------
- ; Get string from extended memory into data segment
- ; dest_name_lab byte label of destination block in ds
- ; source_seg_lab word in memory containing segment of source block
- ; source_off_lab word in memory containing offset of source block
- ; num_imm word number of bytes to move
- ;------------------
- push ds
- mov es,ds
- lea di,dest_name_lab
- mov si,[source_off_lab]
- mov ax,[source_seg_lab]
- mov ds,ax
- mov cx,num_imm
- cld
- rep
- movsb
- pop ds
- endm
-
- ; MISCELLANEOUS
-
- ;------------------
- exit macro code_imm ;exit code for calls by DOS errorlevel
- ;------------------
- ; code_imm byte code for parent or DOS use
- ;------------------
- mov al,code_imm
- mov ah,4ch
- int 21h
- endm
-
- ;------------------
- pushall macro
- ;------------------
- push bp
- push ax
- push bx
- push cx
- push dx
- push ds
- push es
- push si
- push di
- endm
-
- ;------------------
- popall macro
- ;------------------
- pop di
- pop si
- pop es
- pop ds
- pop dx
- pop cx
- pop bx
- pop ax
- pop bp
- endm
-
-